module.exports = {
	/**
	 * 修改数据
	 * @url admin/recharge/sys/update 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: 'ok' };
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		let {
			_id,
			nickname, //添加这条充值方案的nickname
			username, //添加这条充值方案的username
			user_id, //添加这条充值方案的账户id
			recharge_amount,
			bean,
			jiaobiao,
			recharge_text,
			subject,
			judge,
			give_bean,  //多送多少豆
			percentage_user, //xx%的用户选择
			indulgence, //是否特惠充值
			sort,
			invite_code,
			appid,
			appname,
			_add_time,
			_add_time_str
		} = data;
		// 参数验证开始
		if (vk.pubfn.isNull(_id)) return { code: -1, msg: 'id不能为空' };

		console.log("user=", user_id);
		//如果修改时该方案不存在user_id，则取当前用户信息
		if (!user_id) {
			nickname = userInfo.nickname || "nickname";
			username = userInfo.username || "username";
			user_id = userInfo._id || "user_id";
		}

		// 参数验证结束
		let dbName = "b_recharge"; // 表名
		// 执行 数据库 updateById 命令
		await vk.baseDao.updateById({
			dbName,
			id: _id,
			dataJson: {
				nickname, //添加这条充值方案的nickname
				username, //添加这条充值方案的username
				user_id, //添加这条充值方案的账户id
				recharge_amount,
				bean,
				jiaobiao,
				recharge_text,
				subject,
				judge,
				give_bean,  //多送多少豆
				percentage_user, //xx%的用户选择
				indulgence, //是否特惠充值
				sort,
				invite_code,
				appid,
				appname,
				_add_time,
				_add_time_str
			}
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}

}
